package com.chookss.home.logContacts;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.chookss.R;
import com.chookss.Urls;
import com.chookss.base.BaseViewHolderEx;
import com.chookss.base.StaticClass;
import com.chookss.home.entity.LogEntity;
import com.chookss.home.entity.WeekEntity;
import com.chookss.home.publish.PublishLogsActivity;
import com.chookss.mine.personal.PersonalHomeActivity;
import com.chookss.tools.GlideUtils;
import com.chookss.tools.GridSpacingItemDecoration;
import com.chookss.tools.MyEvent;
import com.chookss.tools.MyToast;
import com.chookss.tools.NavigationTools;
import com.chookss.tools.PermissionSpUtils;
import com.chookss.tools.SignUtils2;
import com.chookss.tools.Utils;
import com.chookss.tools.okgoconfig.MyHttpRequest;
import com.chookss.tools.okgoconfig.OkGoUtil;
import com.chookss.tools.okgoconfig.callback.JsonCallback;
import com.chookss.tools.okgoconfig.callback.ObserverCallback;
import com.chookss.tools.okgoconfig.model.LzyResponse;
import com.chookss.view.BasisTimesUtils;
import com.chookss.view.BottomListsDialog;
import com.chookss.view.CircleImageView;
import com.chookss.view.SelectDialogListener;
import com.chookss.view.WeekDialog;
import com.chookss.view.listener.WeekDialogListener;
import com.google.gson.reflect.TypeToken;
import com.johnrambo.ktea.ktExtends.ShareUtils;
import com.lvgroup.hospital.base.BaseAct;
import com.lzy.okgo.model.Response;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.constant.RefreshState;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import io.reactivex.annotations.NonNull;
import io.reactivex.annotations.Nullable;

//分组 日志列表
public class LogGroupsActivity extends BaseAct {

    @BindView(R.id.common_title_txt)
    TextView commonTitleTxt;
    @BindView(R.id.common_right_iv)
    ImageView commonRightIv;
    @BindView(R.id.common_right_iv_ll)
    LinearLayout common_right_iv_ll;
    @BindView(R.id.tvTime)
    TextView tvTime;
    @BindView(R.id.tvTitle)
    TextView tvTitle;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.smrRf)
    SmartRefreshLayout smrRf;
    @BindView(R.id.tvEmpty)
    TextView tvEmpty;
    @BindView(R.id.llNone)
    LinearLayout llNone;
    @BindView(R.id.ivAdd)
    ImageView ivAdd;
    private LogListAdapter adapter;
    private int currentPage = 1;
    private boolean isEnd = false;//是否到底
    private List<LogEntity> list = new ArrayList<>();
    private String owerEmployeeCode = "", teamCode = "", teamName = "", reportType = "";//（ 0 日报 1 周报 2 月报 3 日志）
    private String currentTime = "";//当前时间
    private String choiceTime = "";//选择时间
    private String employeeCode = "";//只看他人日志
    private BottomListsDialog bottomListsDialog = null;
    private List<String> dialogList = new ArrayList<>();
    private int yearChoice = 4, weekChoice;//选择周的时候专用字段
    private boolean isPermissions = false;//是否有权限添加  默认没有

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        setContentView(R.layout.activity_log_groups);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        initState();
        owerEmployeeCode = getIntent().getStringExtra("owerEmployeeCode");
        teamCode = getIntent().getStringExtra("teamCode");
        teamName = getIntent().getStringExtra("teamName");
        reportType = getIntent().getStringExtra("reportType");
        if (reportType.equals("0")) {
            if (PermissionSpUtils.getBoolean(this,"21",false)) {
                isPermissions = true;
            }
        } else if (reportType.equals("1")) {
            if (PermissionSpUtils.getBoolean(this,"22",false)) {
                isPermissions = true;
            }
        } else if (reportType.equals("2")) {
            if (PermissionSpUtils.getBoolean(this,"23",false)) {
                isPermissions = true;
            }
        } else if (reportType.equals("3")) {
            if (PermissionSpUtils.getBoolean(this,"12",false)) {
                isPermissions = true;
            }
        }
        if (isPermissions) {
            ivAdd.setVisibility(View.VISIBLE);
        } else {
            ivAdd.setVisibility(View.GONE);
        }
        commonTitleTxt.setText(teamName);
        common_right_iv_ll.setVisibility(View.VISIBLE);
        LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) commonRightIv.getLayoutParams();
        layoutParams.width = Utils.dip2px(this, 20);
        layoutParams.height = Utils.dip2px(this, 20);
        commonRightIv.setLayoutParams(layoutParams);
        commonRightIv.setBackgroundResource(R.drawable.icon_date_45);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        adapter = new LogListAdapter(R.layout.item_look_log, this, list);
        recyclerView.setAdapter(adapter);
        smrRf.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                if (isEnd) {//has next page
                    MyToast.show("没有更多数据了");
                    loadEnd();
                } else {
                    currentPage++;
                    getLogData();
                }
            }
        });
        smrRf.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                currentPage = 1;
                isEnd = false;
                getLogNum();
                getLogData();
            }
        });
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date(System.currentTimeMillis());
        currentTime = simpleDateFormat.format(date);
        if (reportType.equals("2")) {
            currentTime = currentTime.substring(0, 7);
        }
        if (reportType.equals("1")) {
            tvTime.setText(Utils.changeWeek(currentTime));
            getWeek();
        } else {
            tvTime.setText(Utils.changeCnDate(currentTime));
        }
        smrRf.autoRefresh();
        dialogList.add("只看此人");

    }

    private void getLogNum() {
        Map<String, String> map = new HashMap<>();
        map.put("teamCode", teamCode);
        map.put("reportType", reportType);
        map.put("periodName", currentTime);
        MyHttpRequest.getRequest(Urls.selectReportTeamEmpNum, this, SignUtils2.makeSignStr(map), new JsonCallback<String>() {
            @Override
            public void onSuccess(Response<String> response) {
                loadEnd();
                try {
                    JSONObject jsonObject = new JSONObject(response.body().toString());
                    if (tvTitle == null) {
                        return;
                    }
                    if ("200".equals(jsonObject.getString("code"))) {
                        JSONObject jsonObject1 = jsonObject.getJSONObject("data");
                        int totalNum = Utils.changeNumber(jsonObject1.getString("totalNum"));
                        int compelteNum = Utils.changeNumber(jsonObject1.getString("compelteNum"));
                        if (totalNum - compelteNum < 0) {
                            tvTitle.setText("共" + totalNum + "人，0人未提交");
                        } else {
                            tvTitle.setText("共" + totalNum + "人，" + (totalNum - compelteNum) + "人未提交");
                        }

                    }else {
                        if (jsonObject.getString("code").startsWith("400")) {
                            OkGoUtil.onErrorIntent(jsonObject.getString("code"),jsonObject.getString("msg"));
                        }else{
                            MyToast.show(jsonObject.getString("msg"));
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private void getLogData() {
        Map<String, String> map = new HashMap<>();
        map.put("type", "0");
        map.put("reportType", reportType);
        map.put("startTime", choiceTime);
        map.put("endTime", choiceTime);
        map.put("pageNum", currentPage + "");
        map.put("pageSize", "20");
        map.put("teamCode", teamCode);
        if (!Utils.isNull(employeeCode)) {
            map.put("employeeCode", employeeCode);
        }
        MyHttpRequest.getDefault().postRequest(new TypeToken<LzyResponse<List<LogEntity>>>() {
        }.getType(), null, Urls.getReportList, SignUtils2.makeSignStr(map), false, new ObserverCallback<List<LogEntity>>() {
            @Override
            public void onSuccess(List<LogEntity> data) {
                if (currentPage == 1) {
                    list.clear();
                    adapter.notifyDataSetChanged();
                }
                if (smrRf == null || llNone == null) {
                    return;
                }
                int oldIndex = list.size();
                if (data != null && data.size() > 0) {
                    list.addAll(data);
                    adapter.notifyItemRangeChanged(oldIndex, data.size());
                    smrRf.setVisibility(View.VISIBLE);
                    llNone.setVisibility(View.GONE);
                } else {
                    isEnd = true;
                    if (list.size() == 0) {
                        smrRf.setVisibility(View.GONE);
                        llNone.setVisibility(View.VISIBLE);
                    }
                }
                loadEnd();
            }

            @Override
            public void onError(String errorMsg) {
                loadEnd();
                MyToast.show(Utils.onErrorTips(errorMsg));
            }
        });
    }

    private int timeInt = 0;
    private List<List<WeekEntity>> weekEntityList = new ArrayList<>();
    private List<List<String>> allList = new ArrayList<>();
    private List<List<String>> oldAllList = new ArrayList<>();
    private List<String> yearList = new ArrayList<>();
    private List<String> oldYearList = new ArrayList<>();

    private void getWeek() {
        int year = Calendar.getInstance().get(Calendar.YEAR);
        yearList.add((year - 4) + "年");
        oldYearList.add((year - 4) + "年");
        yearList.add((year - 3) + "年");
        oldYearList.add((year - 3) + "年");
        yearList.add((year - 2) + "年");
        oldYearList.add((year - 2) + "年");
        yearList.add((year - 1) + "年");
        oldYearList.add((year - 1) + "年");
        yearList.add(year + "年");
        oldYearList.add(year + "年");
        yearList.add((year + 1) + "年");
        oldYearList.add((year + 1) + "年");
        weekChoice = Utils.getCurrentWeek(currentTime) - 1;
        if (weekChoice == 0 && 11 == Calendar.getInstance().get(Calendar.MONTH)) {
            yearChoice = yearChoice + 1;
        }
        for (int i = 0; i < yearList.size(); i++) {
            List<String> list = new ArrayList<>();
            List<String> list2 = new ArrayList<>();
            List<WeekEntity> weekEntities = new ArrayList<>();
            allList.add(list);
            oldAllList.add(list2);
            weekEntityList.add(weekEntities);
        }
        for (int i = 0; i < yearList.size(); i++) {
            int y = i;
            Map<String, String> map = new HashMap<>();
            map.put("year", yearList.get(i).substring(0, 4));
            MyHttpRequest.getDefault().getRequest(new TypeToken<LzyResponse<List<WeekEntity>>>() {
            }.getType(), null, Urls.selectWeekByYear, SignUtils2.makeSignStr(map), false, new ObserverCallback<List<WeekEntity>>() {
                @Override
                public void onSuccess(List<WeekEntity> data) {
                    timeInt++;
                    for (int j = 0; j < data.size(); j++) {
                        allList.get(y).add("第" + data.get(j).getWeekNum() + "周(" + data.get(j).getStartTime().substring(5, 10) + "至" + data.get(j).getEndTime().substring(5, 10) + ")");
                        oldAllList.get(y).add("第" + data.get(j).getWeekNum() + "周(" + data.get(j).getStartTime().substring(5, 10) + "至" + data.get(j).getEndTime().substring(5, 10) + ")");
                    }
                    weekEntityList.get(y).addAll(data);
                }

                @Override
                public void onError(String errorMsg) {
                }
            });
        }
    }

    private void loadEnd() {
        if (null != smrRf && smrRf.getState() == RefreshState.Refreshing)
            smrRf.finishRefresh(true);
        if (null != smrRf && smrRf.getState() == RefreshState.Loading)
            smrRf.finishLoadMore(true);
    }

    @OnClick({R.id.common_title_back, R.id.ivAdd, R.id.llTitle, R.id.common_right_iv_ll})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.common_title_back:
                finish();
                break;
            case R.id.ivAdd:
                Intent intentPublish = new Intent(LogGroupsActivity.this, PublishLogsActivity.class);
                intentPublish.putExtra("type", Utils.changeNumber(reportType));
                intentPublish.putExtra("teamName", teamName);
                intentPublish.putExtra("teamCode", teamCode);
                startActivity(intentPublish);
                break;
            case R.id.llTitle:
                Intent intent = new Intent(this, LogManagerCompleteActivity.class);
                intent.putExtra("teamCode", teamCode);
                intent.putExtra("teamName", teamName);
                intent.putExtra("currentTime", currentTime);
                intent.putExtra("owerEmployeeCode", owerEmployeeCode);
                intent.putExtra("reportType", reportType);
                startActivity(intent);
                break;
            case R.id.common_right_iv_ll:
                if ("2".equals(reportType)) {
                    showDatePickDialog(2);
                } else if ("1".equals(reportType)) {
                    if (tvTime == null) {
                        return;
                    }
                    if (timeInt == 6) {
                        allList.clear();
                        allList.addAll(oldAllList);
                        yearList.clear();
                        yearList.addAll(oldYearList);
                        new WeekDialog(LogGroupsActivity.this, yearChoice, weekChoice, yearList, allList, new WeekDialogListener() {
                            @Override
                            public void onClick(String yearIndex, String weekIndex) {
                                for (int i = 0; i < 6; i++) {
                                    if (oldYearList.get(i).equals(yearIndex)) {
                                        for (int j = 0; j < oldAllList.get(i).size(); j++) {
                                            if (oldAllList.get(i).get(j).equals(weekIndex)) {
                                                yearChoice = i;
                                                weekChoice = j;
                                                currentTime = yearIndex.substring(0, 4) + "-" + weekIndex.split("至")[1].substring(0, 5);
                                                tvTime.setText(Utils.changeWeek(currentTime));
                                                choiceTime = currentTime;
                                                smrRf.autoRefresh();
                                            }
                                        }
                                    }
                                }
                            }
                        }).show();

                    } else {
                        showDatePickDialog(0);
                    }

                } else {
                    showDatePickDialog(0);
                }
                break;
        }
    }

    int mYear = 0, mMonth = 0, mDay = 0;
    String monthS = "", dayS = "";

    private void showDatePickDialog(int state) {
        //获取日历的一个实例，里面包含了当前的年月日
        Calendar calendar = Calendar.getInstance();
        if (mYear == 0) {
            mYear = calendar.get(Calendar.YEAR);
            mMonth = calendar.get(Calendar.MONTH);
            mDay = calendar.get(Calendar.DAY_OF_MONTH);
        }
        if (tvTime == null) {
            return;
        }
        BasisTimesUtils.showDatePickerDialog(this, true, "请选择日期", mYear, mMonth, mDay,
                new BasisTimesUtils.OnDatePickerListener() {

                    @Override
                    public void onConfirm(int year, int month, int dayOfMonth) {
                        mYear = year;
                        mMonth = month - 1;
                        mDay = dayOfMonth;
                        if (dayOfMonth > 9) {
                            dayS = dayOfMonth + "";
                        } else {
                            dayS = "0" + dayOfMonth;
                        }
                        if (month > 9) {
                            monthS = month + "";
                        } else {
                            monthS = "0" + month;
                        }
                        if ("2".equals(reportType)) {
                            currentTime = year + "-" + monthS;
                        } else {
                            currentTime = year + "-" + monthS + "-" + dayS;
                        }
                        if ("1".equals(reportType)) {
                            tvTime.setText(Utils.changeWeek(currentTime));
                        } else {
                            tvTime.setText(Utils.changeCnDate(currentTime));
                        }
                        choiceTime = currentTime;
                        smrRf.autoRefresh();
                    }

                    @Override
                    public void onCancel() {
                    }
                }).setDay(state);
    }
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMoonEvent(MyEvent messageEvent) {
        //事件订阅者处理事件
        if (messageEvent.getHashMap() != null) {
            Map<String, String> map = messageEvent.getHashMap();
             if(map.containsKey("Log_Read")){
                int index=Utils.changeNumber(map.get("Log_Read"));
                readData(list.get(index),index);
            }
        } else {
            String msg = messageEvent.getMessage();
            if (Utils.isNull(msg)) {
                return;
            }
            if ("RefreshLogFragment".equals(msg)) {
                //刷新最近列表
                smrRf.autoRefresh();
            }
        }
    }
    class LogListAdapter extends BaseQuickAdapter<LogEntity, BaseViewHolderEx> {
        private Context context;
        private GridSpacingItemDecoration gridSpacingItemDecoration;

        public LogListAdapter(int layoutResId, Context context, @Nullable List<LogEntity> data) {
            super(layoutResId, data);
            this.context = context;
            gridSpacingItemDecoration = new GridSpacingItemDecoration(4, Utils.dip2px(context, 8), false);

        }

        @Override
        protected void convert(BaseViewHolderEx helper, LogEntity item) {
            CircleImageView ivHead = helper.getView(R.id.ivHead);
            TextView tvName = helper.getView(R.id.tvName);
            TextView tvTime = helper.getView(R.id.tvTime);
            RelativeLayout rlMore = helper.getView(R.id.rlMore);
            TextView tv1 = helper.getView(R.id.tv1);
            TextView tv2 = helper.getView(R.id.tv2);
            TextView tv3 = helper.getView(R.id.tv3);
            TextView tv4 = helper.getView(R.id.tv4);
            TextView tv1Init = helper.getView(R.id.tv1Init);
            TextView tv2Init = helper.getView(R.id.tv2Init);
            TextView tv3Init = helper.getView(R.id.tv3Init);
            TextView tv4Init = helper.getView(R.id.tv4Init);
            LinearLayout ll3 = helper.getView(R.id.ll3);
            LinearLayout ll4 = helper.getView(R.id.ll4);
            RecyclerView imgRv = helper.getView(R.id.imgRv);
            LinearLayout llContent = helper.getView(R.id.llContent);
            LinearLayout llRead = helper.getView(R.id.llRead);
            TextView tvRead = helper.getView(R.id.tvRead);
            List<String> picList=new ArrayList<>();
            if (item.getPictureList().size() > 0||item.getVideoPictureList().size() > 0) {
                imgRv.setVisibility(View.VISIBLE);
                LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) imgRv.getLayoutParams();
                params.width = Utils.getScreenWidthPixel(LogGroupsActivity.this) - Utils.dip2px(LogGroupsActivity.this, 74);
                params.height = (Utils.getScreenWidthPixel(LogGroupsActivity.this) - Utils.dip2px(LogGroupsActivity.this, 98)) / 4;
                imgRv.setLayoutParams(params);
                GridLayoutManager gridLayoutManager1 = new GridLayoutManager(context, 4);
                imgRv.setLayoutManager(gridLayoutManager1);
                if (imgRv.getItemDecorationCount() == 0) {
                    imgRv.addItemDecoration(gridSpacingItemDecoration);
                }
            } else {
                imgRv.setVisibility(View.GONE);
            }
            if (item.getPictureList().size() > 0) {
                LogImagsAdapter adapter = null;
                picList.clear();
                if (item.getPictureList().size() >= 4) {
                    picList.addAll(item.getPictureList().subList(0, 4));
                    adapter = new LogImagsAdapter(R.layout.item_log_imges, context,picList,-1,item,helper.getItemPosition() );
                } else {
                    picList.addAll(item.getPictureList());
                    if(item.getVideoPictureList().size()>0){
                        if(item.getVideoPictureList().size()>=(4-item.getPictureList().size())){
                            picList.addAll(item.getVideoPictureList().subList(0, 4-item.getPictureList().size()));
                        }else{
                            picList.addAll(item.getVideoPictureList());
                        }
                    }
                    adapter = new LogImagsAdapter(R.layout.item_log_imges, context, picList,item.getPictureList().size(),item,helper.getItemPosition());
                }
                imgRv.setAdapter(adapter);
            } else {
                if (item.getVideoPictureList().size() >0) {
                    LogImagsAdapter adapter = null;
                    picList.clear();
                    if (item.getVideoPictureList().size() >= 4) {
                        picList.addAll(item.getVideoPictureList().subList(0, 4));
                    } else {
                        picList.addAll(item.getVideoPictureList());
                    }
                    adapter = new LogImagsAdapter(R.layout.item_log_imges, context,picList,0,item,helper.getItemPosition() );
                    imgRv.setAdapter(adapter);
                }
            }

            if (item.getPlayListPage().getList().size() > 0) {
                llRead.setVisibility(View.VISIBLE);
                String names = "";
                for (int i = 0; i < item.getPlayListPage().getList().size(); i++) {
                    if (i < 3) {
                        if (Utils.isNull(names)) {
                            names = names + "" + item.getPlayListPage().getList().get(i).getPlayEmployeeName();
                        } else {
                            names = names + "、" + item.getPlayListPage().getList().get(i).getPlayEmployeeName();
                        }
                    }
                }
                if (Utils.changeNumber(item.getPlayListPage().getTotal()) > 3) {
                    tvRead.setText(names + "等" + item.getPlayListPage().getTotal() + "人浏览过");
                } else {
                    tvRead.setText(names + item.getPlayListPage().getTotal() + "人浏览过");
                }
            } else {
                llRead.setVisibility(View.GONE);
            }
            GlideUtils.loadAvatar(LogGroupsActivity.this, item.getHeadPhotoThumbUrl(), ivHead);
            tvTime.setText(Utils.getAccurateDate(item.getCreateTime()));
            int sort = Utils.changeNumber(item.getSort());
            if (sort == 0) {
                sort = 1;
            }
            LinearLayout.LayoutParams tv1Params = (LinearLayout.LayoutParams) tv1Init.getLayoutParams();
            LinearLayout.LayoutParams tv2Params = (LinearLayout.LayoutParams) tv2Init.getLayoutParams();
            if ("0".equals(item.getReportType())) {
                tvName.setText(item.getEmployeeName() + Utils.getCurrentDay(item.getReportType(), item.getCreateTime()) + "(" + sort + ")");
                ll3.setVisibility(View.VISIBLE);
                ll4.setVisibility(View.VISIBLE);
                tv1Params.width = Utils.dip2px(LogGroupsActivity.this, 84);
                tv1Params.gravity = Gravity.RIGHT;
                tv2Params.width = Utils.dip2px(LogGroupsActivity.this, 84);
                tv2Params.gravity = Gravity.RIGHT;
                tv1Init.setText("今日完成工作：");
                tv2Init.setText("未完成工作：");
                tv3Init.setText("需协调工作：");
                tv4Init.setText("明日工作计划：");
                tv1.setText(item.getFinishWork());
                tv2.setText(item.getUnFinishWork());
                tv3.setText(item.getNeedHelpWork());
                tv4.setText(item.getNextWorkPlan());
            } else if ("1".equals(item.getReportType())) {
                tvName.setText(item.getEmployeeName() + Utils.getCurrentDay(item.getReportType(), item.getCreateTime()) + "(" + sort + ")");
                ll3.setVisibility(View.VISIBLE);
                ll4.setVisibility(View.VISIBLE);
                tv1Params.width = Utils.dip2px(LogGroupsActivity.this, 84);
                tv1Params.gravity = Gravity.RIGHT;
                tv2Params.width = Utils.dip2px(LogGroupsActivity.this, 84);
                tv2Params.gravity = Gravity.RIGHT;
                tv1Init.setText("本周完成工作：");
                tv2Init.setText("本周工作总结：");
                tv3Init.setText("需协调与帮助：");
                tv4Init.setText("下周工作计划：");
                tv1.setText(item.getFinishWork());
                tv2.setText(item.getUnFinishWork());
                tv3.setText(item.getNeedHelpWork());
                tv4.setText(item.getNextWorkPlan());
            } else if ("2".equals(item.getReportType())) {
                tvName.setText(item.getEmployeeName() + Utils.getCurrentDay(item.getReportType(), item.getCreateTime()) + "(" + sort + ")");
                ll3.setVisibility(View.VISIBLE);
                ll4.setVisibility(View.VISIBLE);
                tv1Params.width = Utils.dip2px(LogGroupsActivity.this, 84);
                tv1Params.gravity = Gravity.RIGHT;
                tv2Params.width = Utils.dip2px(LogGroupsActivity.this, 84);
                tv2Params.gravity = Gravity.RIGHT;
                tv1Init.setText("本月工作内容：");
                tv2Init.setText("本月工作总结：");
                tv3Init.setText("需帮助与支持：");
                tv4Init.setText("下月工作计划：");
                tv1.setText(item.getFinishWork());
                tv2.setText(item.getUnFinishWork());
                tv3.setText(item.getNeedHelpWork());
                tv4.setText(item.getNextWorkPlan());
            } else {
                tvName.setText(item.getEmployeeName() + Utils.getCurrentDay(item.getReportType(), item.getCreateTime()));
                ll3.setVisibility(View.GONE);
                ll4.setVisibility(View.GONE);
                tv1Params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
                tv1Params.gravity = Gravity.LEFT;
                tv2Params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
                tv2Params.gravity = Gravity.LEFT;
                tv1Init.setText("日志标题：");
                tv2Init.setText("日志内容：");
                tv1.setText(item.getTitle());
                tv2.setText(item.getContent());
            }
            tv1Init.setLayoutParams(tv1Params);
            tv2Init.setLayoutParams(tv2Params);
            helper.getItemView().setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    readData(item, helper.getItemPosition());
                    Intent intent = new Intent(LogGroupsActivity.this, LogDetailActivity.class);
                    intent.putExtra("data", item);
                    intent.putExtra("title", tvName.getText().toString());
                    startActivity(intent);
                }
            });
            ivHead.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent(LogGroupsActivity.this, PersonalHomeActivity.class);
                    intent.putExtra("employeeCode", item.getEmployeeCode());
                    startActivity(intent);
                }
            });
            rlMore.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    bottomListsDialog = new BottomListsDialog(context, dialogList, new SelectDialogListener() {
                        @Override
                        public void onCancel() {

                        }

                        @Override
                        public void onListItemClick(int position, List<String> list) {

                            if (Utils.isNull(employeeCode)) {
                                employeeCode = item.getEmployeeCode();
                                dialogList.set(0, "取消只看此人");
                            } else {
                                employeeCode = "";
                                dialogList.set(0, "只看此人");
                            }
                            smrRf.autoRefresh();
                            bottomListsDialog.dismiss();
                        }
                    });
                    bottomListsDialog.show();
                }
            });
        }
    }
    private void readData(LogEntity logEntity, int position) {
        Map<String, String> allmap = new HashMap<>();
        allmap.put("reportCode", logEntity.getReportCode());
        allmap.put("reportType", logEntity.getReportType());
        allmap.put("reportEmployeeCode", logEntity.getEmployeeCode());
        MyHttpRequest.postRequest(Urls.getReportById, this, SignUtils2.makeSignStr(allmap), new JsonCallback<String>() {
            @Override
            public void onSuccess(Response<String> response) {
                try {
                    JSONObject jsonObject = new JSONObject(response.body().toString());
                    if(jsonObject.getString("code").equals("200")) {
                        JSONArray jsonArray=jsonObject.getJSONArray("data");
                        list.get(position).getPlayListPage().getList().clear();
                        for (int i = 0; i <jsonArray.length(); i++) {
                            JSONObject jsonObject1 =jsonArray.getJSONObject(i);
                            LogEntity.PlayListPageBean.ListBean listBean = new LogEntity.PlayListPageBean.ListBean();
                            listBean.setPlayEmployeeName(jsonObject1.getString("playEmployeeName"));
                            list.get(position).getPlayListPage().getList().add(listBean);
                        }
                        list.get(position).getPlayListPage().setTotal(jsonObject.getString("total"));
                        adapter.notifyItemChanged(position);
                    }else{
                        if (jsonObject.getString("code").startsWith("400")) {
                            OkGoUtil.onErrorIntent(jsonObject.getString("code"),jsonObject.getString("msg"));
                        }else{
                            MyToast.show(jsonObject.getString("msg"));
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });
    }
}
